/*
*Copyright (c) Nikhil Jain.
*Project ICARUS, communications and 
*artificial intelligence.
*/



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package javadrone.remotepackage;

//~--- non-JDK imports --------------------------------------------------------

import javadrone.Server;

import simbad.sim.Box;
import simbad.sim.EnvironmentDescription;
import simbad.sim.Wall;

//~--- JDK imports ------------------------------------------------------------

import java.io.Serializable;

import java.util.ArrayList;

import javax.vecmath.Color3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

/**
 *
 * @author Nikzzay
 */
public class RemoteBootPackage implements Serializable {
    private ArrayList<RemoteWall>            arw = new ArrayList<>();
    private ArrayList<RemoteBox>             arb = new ArrayList<>();
    private transient EnvironmentDescription led = new EnvironmentDescription();
    private boolean                          backgroundMode;
    private RemoteEnvironmentDescription     red;

    public RemoteBootPackage(EnvironmentDescription led) {
        this.red = new RemoteEnvironmentDescription(led);
        red.fill(this.led);
    }

    public RemoteBootPackage(RemoteEnvironmentDescription red) {
        this.red = red;
        red.fill(led);
    }

    public Box addBox(Vector3d pos, Vector3f extent, Color3f color) {
        RemoteBox rb = new RemoteBox(pos, extent, color);

        arb.add(rb);

        return rb.build(led);
    }

    public Box addBox(Vector3d pos, Vector3f extent) {
        return addBox(pos, extent, null);
    }

    public Wall addWall(Vector3d pos, float length, float width, float height) {
        RemoteWall rw = new RemoteWall(pos, length, width, height);

        arw.add(rw);

        return rw.build(led);
    }

    public Wall addWall(Vector3d pos, float length, float height) {
        RemoteWall rw = new RemoteWall(pos, length, height);

        arw.add(rw);

        return rw.build(led);
    }

    public EnvironmentDescription getEnvironmentDescription() {
        EnvironmentDescription ed = new EnvironmentDescription();

        red.fill(ed);

        for (RemoteBox rbx : arb) {
            ed.add(rbx.build(ed));
        }

        for (RemoteWall rwx : arw) {
            ed.add(rwx.build(ed));
        }

        return ed;
    }

    public void fill(EnvironmentDescription ed) {
        red.fill(ed);

        for (RemoteBox rbx : arb) {
            ed.add(rbx.build(ed));
        }

        for (RemoteWall rwx : arw) {
            ed.add(rwx.build(ed));
        }
    }

    public Box[] getBoxes() {
        EnvironmentDescription ed    = getEnvironmentDescription();
        Box[]                  boxes = new Box[arb.size()];
        int                    i     = 0;

        for (RemoteBox rbx : arb) {
            boxes[i++] = rbx.build(ed);
        }

        return boxes;
    }

    public Wall[] getWalls() {
        EnvironmentDescription ed    = getEnvironmentDescription();
        Wall[]                 walls = new Wall[arw.size()];
        int                    i     = 0;

        for (RemoteWall rwx : arw) {
            walls[i++] = rwx.build(ed);
        }

        return walls;
    }

    public boolean backgroundMode() {
        return backgroundMode;
    }

    public void setMode(boolean bm) {
        this.backgroundMode = bm;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
